/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package business;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author stana
 */
public class MD5Algorithm {
    public static String getMD5(String plainText) throws NoSuchAlgorithmException, UnsupportedEncodingException
    {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] bytesOfMessage = plainText.getBytes("UTF-8");
        byte[] digest = md.digest(bytesOfMessage);

        BigInteger bigInt = new BigInteger(1, digest);
        String hashtext = bigInt.toString(16);
// Now we need to zero pad it if you actually want the full 32 chars.
        while (hashtext.length() < 32)
        {
            hashtext = "0" + hashtext;
        }
        return hashtext;
    }

}
